#ifndef _LICENSE_PROXY_H
#define _LICENSE_PROXY_H

#include <string>
#include <list>
using namespace std;
#include "../../../Internet/HttpRequestProxy/HttpRequestProxy.h"
USING_HTTP_REQUEST_PROXY

#define LICENSE_PROXY_NAMESPACE			LicenseProxy
#define LICENSE_PROXY_NAMESPACE_BEGIN	namespace LICENSE_PROXY_NAMESPACE {
#define LICENSE_PROXY_NAMESPACE_END		}
#define USING_LICENSE_PROXY				using namespace LICENSE_PROXY_NAMESPACE;

LICENSE_PROXY_NAMESPACE_BEGIN

//@ErrorMark(type = ErrorType.Fatal, description="Some internal exception occurs in server runtime")
#define ServerInternalError = -1;
//@ErrorMark(type = ErrorType.Warning, description="The SN text is not exist")
#define InvalidSN = -2;
//@ErrorMark(type = ErrorType.Warning, description="The SN text is not actived")
#define NotActivedSN = -3;
//@ErrorMark(type = ErrorType.Warning, description="The actived count of such SN is over the max active counts")
#define ActiveOverCount = -4;

enum LicenseRequestType {
	BeginRequest = 0,
	Active_License,
	Check_License,
	EndRequest,
};

enum HardwareInfoType {
	System = 0,
	Mainboard,
	Disc,
	CPU,
	NIC,
	BIOS,
};

struct tMachineInfo {
	unsigned int info;
	HardwareInfoType type;
};
typedef list<tMachineInfo> tMachineInfoList;

struct tActiveCodeInfo {
	string active_code;
	HardwareInfoType type;
};
typedef list<tActiveCodeInfo> tActiveCodeList;

struct tLicenseInfo {
	string serialNumber;
	unsigned short product_id;
};

class ILicenseRequestListener;
class ILicenseProxy
{
public:
	virtual void Initialize(const string& serviceURL, const int& port = 80, const bool& encryptData = true) = 0;
	virtual void Destroy() = 0;
	virtual void SetServiceURL(const string& serviceURL, const int& port = 80) = 0;
	virtual void ActiveLicense(const tLicenseInfo& license, const tMachineInfoList& machineInfo) = 0;
	virtual void CheckLicense(const tLicenseInfo& license) = 0;
	virtual void SetRequestListener(ILicenseRequestListener* listener) = 0;

	static ILicenseProxy* CreateLicenseProxy();
};

class ILicenseRequestListener
{
public:
	virtual void OnRequestFailed(const LicenseRequestType& type, const tErrorInfo* error) = 0;

	/**
	Param value:
	type = Active_License, param = tActiveCodeList*
	**/
	virtual void OnRequestSuccess(const LicenseRequestType& type, void* param = NULL) = 0;
};

LICENSE_PROXY_NAMESPACE_END

#endif //_LICENSE_PROXY_H